package com.android.nextBus.Activities;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.android.nextBus.JSON.GetBusStopsJSON;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class NextBusAndoridStandaloneActivity extends Activity {
	
	public static final String JSON_BUS_STOP_DATA_NAME_KEY = "name";
	public static final String JSON_BUS_STOP_DATA_ID_KEY = "id";
	public static final String JSON_BUS_STOP_DATA_LAT_KEY = "lat";
	public static final String JSON_BUS_STOP_DATA_STOPID_KEY = "stopId";
	public static final String JSON_BUS_STOP_DATA_DESC_KEY = "desc";
	public static final String JSON_BUS_STOP_DATA_STREET_KEY = "street";
	public static final String JSON_BUS_STOP_DATA_LON_KEY = "lon";
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		TextView tv = (TextView) findViewById(R.id.text);

		/*
		 * Use this commented method for XML Get request
		ArrayList<BusStopData> data = (ArrayList<BusStopData>) GetBusStops
				.getBusStops("");

		tv.setText(data.get(0).getStopId() + " STOP id = "
				+ data.get(0).getName());
				*/
		
		//JSON get request
	//	String BusStopDataFeed = GetBusStopsJSON.getBusStops("",false);
		String data = null;
		try {
			//JSONArray jsonArray = new JSONArray(BusStopDataFeed);
			//Log.i(" ----",
			//		"Number of entries " + jsonArray.length());
		/*	JSONObject jsonObject = new JSONObject(BusStopDataFeed);
					//jsonArray.getJSONObject(0);
			
			//use the Key value pairs to get the JSON data from one object
			data = jsonObject.getString(JSON_BUS_STOP_DATA_NAME_KEY);
			data += ", " + jsonObject.getString(JSON_BUS_STOP_DATA_DESC_KEY);
			data += ", " + jsonObject.getString(JSON_BUS_STOP_DATA_STREET_KEY);
			data += ", (" + jsonObject.getString(JSON_BUS_STOP_DATA_LAT_KEY);
			data += " , " + jsonObject.getString(JSON_BUS_STOP_DATA_LON_KEY) + ")";
			*/
			/**
			 * Parse here to get all the data 
			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject jsonObject = jsonArray.getJSONObject(i);
				
			}
			*/
		} catch (Exception e) {
			e.printStackTrace();
		}
	/*	
		
		//Set the text view's content to be the Raw JSON data and 
		//An example parsed data
		tv.setText("Raw JSON Data \n " +
				"----------------- " +
				"\n "
				+ BusStopDataFeed 
				+"\n" +
				"-----------------" +
				"  \n"
				+"Example JSON parse " +
				"\n "
				+"---------------- " +
				"\n"
				+ data);
				*/
	}
}